package com.lihepeng.leecode.array2;

/**
 * 二维数组的顺时针旋转 90度
 */
public class Solution48 {
    /**
     * 思路 按照矩形 先按照对角线进行翻转
     * 然后按照行进行翻转
     * 结果就是顺时针旋转90度
     * @param matrix
     */
    public void rotate(int[][] matrix) {
        int n = matrix.length;
        for (int i =0; i<n ;i++) {
            for (int j=i;j<n;j++) {
                int temp =  matrix[i][j];
                matrix[i][j] = matrix[j][i];
                matrix[j][i] = temp;
            }
        }
        // 然后逐行翻转
        for (int i=0;i<n;i++) {
            revert(matrix[i]);
        }
    }
    private void revert(int[]arrs){
        int left =0;
        int right = arrs.length-1;
        while (left <=right)  {
            int temp = arrs[left];
            arrs[left] = arrs[right];
            arrs[right] = temp;
            left++;
            right--;
        }

    }

}
